<?php
namespace Lib\Event;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/27 0027
 * Time: 21:22
 */
class Event implements \Lib\Event\EventListenInterface
{
    public static $events = [];

    /**
     * @description:
     * @auth:yfl
     * @email:554665488@qq.com
     * @param $event :事件名称
     * @param $callback :事件回调
     */
    public static function register($event, $callback)
    {
        $event = strtolower($event);
        // TODO: Implement register() method.
        if (!isset(self::$events[$event])) {
            self::$events[$event] = [];
        }
        self::$events[$event] = ['callback' => $callback];
    }

    public static function trigger($event, $params = [])
    {
        // TODO: Implement handel() method.
        $event = strtolower($event);
        if (isset(self::$events[$event])) {
            if (self::$events[$event]['callback'] instanceof \Closure) {
//                call_user_func_array(self::$events[$event]['callback'], $params);
                call_user_func(self::$events[$event]['callback'], $params);
            } else {
//                ['obj','fun']
                call_user_func(self::$events[$event]['callback'], $params);
            }
        }
        return false;
    }

}